﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shadow : MonoBehaviour {

    private Transform player;
    private SpriteRenderer playerSprite;
    private SpriteRenderer theSprite;

    public float activeTime;
    private float timer;
    public float fadeMultipler;
    
    
	// Use this for initialization
	void  OnEnable() {
        player = GameObject.Find("Player").transform;
        playerSprite = player.GetComponent<SpriteRenderer>();
        theSprite = GetComponent<SpriteRenderer>();
        timer = activeTime;

        theSprite.color = new Color(0.5f, 0.5f, 1, 1);
        theSprite.sprite = playerSprite.sprite;
        theSprite.flipX = playerSprite.flipX;
        transform.position = player.position;
        transform.rotation = player.rotation;
        transform.localScale = player.localScale;
	}
	
	// Update is called once per frame
	void Update () {
        timer -= Time.deltaTime;
        theSprite.color = new Color(0.5f, 0.5f, 1, theSprite.color.a* fadeMultipler);
        if (timer <= 0)
        {
            //ShadowPool.Instance.ReturnPool(gameObject);
            ObjectPool.Instance.ReturnPool("shadow", gameObject);
        }
	}
}
